package bls.juejin.cn.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.bx.pay.WPayApplication;
import com.bx.third.wxpay.WXPayCallback;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

/**
 * 
 * 微信支付 回调类 & 微信分享 所需类
 * 
 * 要保证回调类WXPayEntryActivity.java文件必须位于包名的wxapi目录下，否则会导致无法回调的情况(微信官方约定)
 * */
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

	private IWXAPI api;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		api = WXAPIFactory.createWXAPI(this, WPayApplication.getWxPayAppId(),
				false);
		api.handleIntent(getIntent(), this);
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {
		WXPayCallback.call(this, resp);
		this.finish();
	}

}